<template>
  <div class="DecRoot">
    <el-card class="box-card">
      <el-tabs v-model="activeName">
        <el-tab-pane label="所在市场" name="first">
          <el-button
            type="primary"
            icon="el-icon-plus"
            @click="dialogVisible = true"
            plain
            style="margin-bottom: 20px"
            >新增</el-button
          >
          <el-table
            :data="tableData"
            style="width: 100%"
            height="62vh"
            header-cell-class-name="tableHeader"
            stripe
          >
            <el-table-column label="序号" type="index" width="50">
            </el-table-column>
            <el-table-column prop="name" label="市场名"> </el-table-column>

            <el-table-column prop="address" label="操作" width="100">
              <template slot-scope="scope">
                <el-tooltip
                  class="item"
                  effect="dark"
                  content="编辑"
                  placement="top"
                >
                  <img
                    @click="edit(scope.row)"
                    src="@/assets/image/icon/edit.png"
                    class="iconImg"
                    alt=""
                  />
                </el-tooltip>
                <el-popconfirm
                  title="确定要删除该条所在市场吗？"
                  @confirm="deleteContent(scope.row)"
                >
                  <template slot="reference">
                    <i
                      class="el-icon-delete"
                      style="font-size: 25px; color: #409eff; cursor: pointer"
                    ></i>
                  </template>
                </el-popconfirm>
              </template>
            </el-table-column>
          </el-table>
        </el-tab-pane>
        <el-tab-pane label="首页公告" name="gonggao">
          <el-form ref="form" :model="ggForm" label-width="100px">
            <el-form-item label="是否显示：">
              <el-switch v-model="ggForm.flag"> </el-switch>
            </el-form-item>
            <el-form-item label="公告内容：">
              <el-input
                style="width: 500px"
                v-model="ggForm.value"
                type="textarea"
                :autosize="{ minRows: 4 }"
              ></el-input>
            </el-form-item>
            <el-form-item label=" " label-width="100px">
              <el-button
                @click="updateSystemSettingInfo"
                type="primary"
                style="margin-left: 100px; margin-top: 20px"
                >保存</el-button
              >
            </el-form-item>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="首页广告语" name="homeGGY">
          <homeGGY></homeGGY>
        </el-tab-pane>
        <el-tab-pane label="首页菜单" name="homeCd">
          <homeCd></homeCd>
        </el-tab-pane>
        <el-tab-pane label="童装频道" name="pindao">
          <tzpd></tzpd>
        </el-tab-pane>
        <el-tab-pane label="宝贝筛选价格区间" name="price">
          <price></price>
        </el-tab-pane>
        <el-tab-pane label="宝贝筛选你可能再找" name="zz">
          <knzz></knzz>
        </el-tab-pane>
      </el-tabs>
    </el-card>
    <el-dialog :visible.sync="dialogVisible" width="30%" class="newDialog">
      <div class="DiaLogHeader">
        <div class="titlebOX">
          {{ form.id ? "编辑市场" : "新增市场" }}
        </div>
        <div class="chahao" @click="dialogVisible = false">
          <i class="el-icon-close"></i>
        </div>
      </div>
      <el-divider></el-divider>
      <div style="padding: 10px">
        <el-form ref="form" :model="form" label-width="80px">
          <el-form-item label="市场名：">
            <el-input v-model="form.name"></el-input>
          </el-form-item>
        </el-form>
      </div>
      <div class="btnBox">
        <el-button type="primary" @click="save"> 确定</el-button>
        <el-button @click="dialogVisible = false"> 取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
  
  <script>
import {
  selectMarketLocation,
  saveMarketLocation,
  updateMarketLocation,
  deleteMarketLocation,
  selectSystemSettingInfoByName,
  updateSystemSettingInfo,
} from "@/api/DataManagement";
import tzpd from "./components/tzpd.vue";
import price from "./components/price.vue";
import knzz from "./components/knzz.vue";
import homeGGY from "./components/homeGGY.vue";
import homeCd from "./components/homeCd.vue";
export default {
  components: { tzpd, price, knzz, homeGGY,homeCd },
  name: "aboutUs",
  data() {
    return {
      activeName: "first",
      tableData: [],
      dialogVisible: false,
      form: {},
      ggForm: {},
      pdForm: {},
    };
  },
  created() {
    this.selectMarketLocation();
    this.selectSystemSettingInfoByName();
  },
  methods: {
    //保存公告
    updateSystemSettingInfo() {
      updateSystemSettingInfo(this.ggForm).then((daa) => {
        if (data.code == 200) {
          this.$message.success("操作成功");
          this.selectSystemSettingInfoByName();
        }
      });
    },
    //获取公告
    selectSystemSettingInfoByName() {
      selectSystemSettingInfoByName({
        keyWord: "公告",
      }).then((data) => {
        this.ggForm = data.data;
      });
    },
    //删除市场
    deleteContent(row) {
      deleteMarketLocation({
        idList: row.id,
        nameKeyWord: "Market",
      }).then((data) => {
        if (data.code == 200) {
          this.$message.success("操作成功");
          this.selectMarketLocation();
        }
      });
    },
    save() {
      let params = {};
      if (!this.form.id) {
        params = {
          name: this.form.name,
          nameKeyWord: "Market",
        };
        saveMarketLocation(params).then((data) => {
          if (data.code == 200) {
            this.$message.success("操作成功");
            this.dialogVisible = false;
            this.selectMarketLocation();
          }
        });
      } else {
        params = {
          id: this.form.id,
          name: this.form.name,
          nameKeyWord: "Market",
        };
        updateMarketLocation(params).then((data) => {
          if (data.code == 200) {
            this.$message.success("操作成功");
            this.dialogVisible = false;
            this.selectMarketLocation();
          }
        });
      }
    },
    edit(row) {
      this.form = JSON.parse(JSON.stringify(row));
      this.dialogVisible = true;
    },
    //获取所在市场
    selectMarketLocation() {
      selectMarketLocation({
        nameKeyWord: "Market",
      }).then((data) => {
        this.tableData = data.data;
      });
    },
  },
  watch: {
    dialogVisible() {
      if (!this.dialogVisible) {
        this.form = {};
      }
    },
  },
};
</script>
  
        <style scoped lang="scss">
/deep/ .el-card__body {
  min-height: 80vh;
}
.btnBox {
  display: flex;
  justify-content: center;
  background: #fff;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  position: absolute;
  bottom: 0;
  width: 100%;
  padding: 10px 0;

  .btnImg {
    width: 14px;
    height: 14px;
    vertical-align: middle;
  }
}

.DecRoot {
  padding: 20px;
  padding-left: 5px;
  padding-bottom: 0;

  .newCard {
    height: 75vh;
    margin-top: 20px;
  }

  /deep/ .el-button {
    padding: 9px 15px;
  }

  .el-card {
    .headerBox {
      display: flex;
      justify-content: space-between;
      align-items: center;

      .leftBox {
        display: flex;
        align-items: center;
        font-size: 18px;
        font-weight: 700;

        /deep/ .el-form-item {
          margin-bottom: 0;
        }

        /deep/ .el-input--suffix {
          width: 200px;
        }
      }
    }

    /deep/ .tableHeader {
      background: #edf3ff;
      font-weight: 700;
      color: #666666;
    }

    .iconImg {
      width: 20px;
      height: 20px;
      cursor: pointer;
      margin-right: 10px;
    }

    .pagination {
      display: flex;
      justify-content: space-between;
      margin-top: 10px;

      /deep/ .el-pagination__editor.el-input .el-input__inner {
        height: 28px !important;
      }

      /deep/ .el-input--mini .el-input__inner {
        height: 28px !important;
      }
    }
  }
}
</style>
      <style scoped lang="scss">
.titlebOXSA {
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 20px;
}
.newDialog {
  /deep/ .el-divider {
    margin: 0px;
  }
  /deep/ .el-dialog__header {
    padding: 0;
  }
  /deep/ .el-form-item__content {
    width: 75%;
  }
  /deep/ .el-select {
    width: 100%;
  }
  /deep/ .tableHeader {
    background: #edf3ff;
    font-weight: 700;
    color: #666666;
    padding: 5px 0;
  }
  .btnBox {
    display: flex;
    justify-content: center;
    background: #fff;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
    position: absolute;
    bottom: 0;
    width: 100%;
    padding: 10px 0;
    .btnImg {
      width: 14px;
      height: 14px;
      vertical-align: middle;
    }
    /deep/ .el-button {
      padding: 10px 20px;
    }
  }
  .DiaLogHeader {
    display: flex;
    padding: 10px 20px;
    justify-content: space-between;
    .titlebOX {
      font-size: 16px;
      font-weight: 700;
    }
    .chahao {
      width: 20px;
      height: 20px;
      background-image: url("@/assets/image/icon/chahao.png");
      background-size: 100% 100%;
      text-align: center;
      line-height: 20px;
      color: #e65f00;
      cursor: pointer;
    }
  }
  /deep/ .el-input {
    width: 100% !important;
  }
}
/deep/ .el-dialog__header {
  font-weight: 700;
}
/deep/ .demo-ruleForm {
  padding: 10px;
}

/deep/ .el-form-item {
  margin-bottom: 8px;
}
/deep/ .el-form-item__error {
  z-index: 99;
}
/deep/ .el-dialog__body {
  padding: 0;
  padding-top: 10px;
  padding-bottom: 60px;
}
.dialogTextBox {
  font-size: 14px;
  color: #000000;
}
</style>
  